<template>
  <div id="app">
    <transition :name="transition">
      <keep-alive>
        <router-view class="router"></router-view>
      </keep-alive>
    </transition>
  </div>
</template>

<script>
export default {
  data() {
    return {
      transition: "slide-right",
      routerStack: []
    };
  },
  watch: {
    $route(to, from) {
      const fullPath = from.fullPath;
      const lastPath = this.routerStack[this.routerStack.length - 1];
      if (fullPath === lastPath) {
        this.transition = "slide-left";
        this.routerStack.pop();
      } else {
        this.transition = "slide-right";
        this.routerStack.push(to.fullPath);
      }
    }
  }
};
</script>

<style lang="scss">
.router {
  transition: all 0.2s;
}

/*slide*/
.slide-left-enter,
.slide-right-leave-active {
  opacity: 0;
  transform: translate(-50px, 0);
}
.slide-left-leave-active,
.slide-right-enter {
  opacity: 0;
  transform: translate(50px, 0);
}
// #app {
//   font-family: "Avenir", Helvetica, Arial, sans-serif;
//   -webkit-font-smoothing: antialiased;
//   -moz-osx-font-smoothing: grayscale;
//   text-align: center;
//   color: #2c3e50;
// }
// #nav {
//   padding: 30px;
//   a {
//     font-weight: bold;
//     color: #2c3e50;
//     &.router-link-exact-active {
//       color: #42b983;
//     }
//   }
// }
</style>
